SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE FUNCTION dbo.tvfGetInstByNAVDateAndFund (@FundId VARCHAR(10),@AsOfDate DATE)
RETURNS TABLE 
AS
RETURN	(

SELECT DISTINCT i.InstrName, i.InstrumentId FROM  fsfundModel.Reporting.Asset a 
INNER JOIN  FSFundmodel.Reporting.Instrument i ON a.ExportId = i .ExportId 
AND i.InstrumentId = a.InstrumentId

WHERE a.ExportId = (SELECT MAX(e.ExportId) FROM FSFundModel.Reporting.Export e WHERE e.FundId = @FundId AND e.NAVDate = @AsOfDate)
AND a.IsActiveEndOfDay =1


)



GO
